#define _CRT_SECURE_NO_WARNINGS 1

#define _CRT_SECURE_NO_WARNINGS 1
#include"Queue.h"
void QueueInit(Queue* pq)
{
	assert(pq);
	pq->front = pq->rear = NULL;
	pq->size = 0;
}
void QueuePush(Queue* pq, QueueType val)
{
	assert(pq);
	QNode* ret = (QNode*)malloc(sizeof(QNode));
	assert(ret);
	ret->val = val;
	if (pq->front == NULL)
	{
		pq->front = pq->rear = ret;
	}
	else
	{
		pq->rear->next = ret;
		pq->rear = ret;
	}
	pq->size++;
}
void QueuePop(Queue* pq)
{
	assert(pq);
	assert(pq->front);
	if (pq->front == pq->rear)
	{
		pq->front = pq->rear = NULL;
	}
	else
	{
		pq->front = pq->front->next;
	}
	pq->size--;

}


QueueType QueueFront(Queue* pq)
{
	assert(pq);
	assert(pq->front);
	return pq->front->val;

}
QueueType QueueRear(Queue* pq)
{
	assert(pq);
	assert(pq->rear);
	return pq->rear->val;

}

int QueueSize(Queue* pq)
{
	return pq->size;
}
bool QueueEmpty(Queue* pq)
{
	return pq->size == 0;
}

void QueueDestroy(Queue* pq)
{
	if (pq->front != NULL)
	{
		QNode* ret = pq->front;
		while (ret)
		{
			QNode* del = ret;
			ret = ret->next;
			free(del);
		}

	}
	pq->front = pq->rear = NULL;
	pq->size = 0;

}